/*
 * @Author: Otway
 * @Date: 2019-01-09 11:16:08
 * @LastEditors: Otway
 * @LastEditTime: 2019-08-30 18:50:09
 * @copyright: h-visions
 */
import React, { PureComponent } from 'react';
import * as ProductionOrderService from '../../../axios/ProductionOrder'
import {
  Row,
  Col,
  Form,
  Cascader,
} from 'antd';
const FormItem = Form.Item;
const formItemLayout = {
  // 抽屉里面Form。二列的布局比例
  labelCol: {
    span: 6
  },
  wrapperCol: {
    span: 18
  }
};

class PaiGongForm extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      addFrom: [],
      options: [],
      groupList: []
    }
  }
  componentDidMount() {
    ProductionOrderService.findGroupAll().then(res => {
      const addFrom = res.data.data
      // console.log(addFrom, '派工班组查询');
      let options = []
      for (let i = 0; i < addFrom.length; i++) {
        let childrens = []
        for (let j = 0; j < addFrom[i].list.length; j++) {
          childrens.push({ value: addFrom[i].list[j].groupCode + '_' + addFrom[i].list[j].groupName, label: addFrom[i].list[j].groupName })
        }
        options.push({ value: addFrom[i].workShop, label: addFrom[i].workShop, children: childrens })
      }
      this.setState({
        addFrom,
        options
      });
    })
  }
  render() {
    const {
      form: { getFieldDecorator },
    } = this.props;
    const { options } = this.state;
    return (
      <Form >
        <Row>
          <Col span={24}>
            <FormItem {...formItemLayout} label={'班组'}>
              {getFieldDecorator('groupList', {
                rules: [
                  {
                    required: true,
                    message: '请选择班组'
                  }
                ]
                // initialValue: [options[0].value, options[0].children[0].value],
              })(<Cascader
                allowClear={false}
                options={options}
              // onChange={this.onChange}
              />)}
            </FormItem>
          </Col>
        </Row>
      </Form>
    );
  }
}

export default Form.create()(PaiGongForm);
